package gxprod.androidai;

import gxprod.androidai.regex.MatchResult;

/**
 * A background process. This runs in a separate thread entirely to prevent GUI lock up.
 * Operations can be canceled if needed
 * @author josh
 *
 */
public class Operation {

	public boolean isCompleated = false;
	public boolean isSucessful;
	public ParmedRunnable Action;
	
	public Operation(ParmedRunnable action) {
		Action = action;
	}
	
	public void execute(final MatchResult result, final Object o, final BubbleAdapter adapter) {
		isSucessful =  Action.run(result, adapter, o);
		isCompleated = true;
		adapter.postUpdate();
	}
	
	public boolean cancel() {
		if(Action == null)
			return false;
		
		return Action.cancel();
	}
	
	public interface ParmedRunnable {
		public boolean cancel();
		public boolean run(MatchResult result, BubbleAdapter adapter, Object o);
	}
}
